import { Component, OnDestroy } from '@angular/core';

import { Util } from '../../../utils/util';

import { WordDetailHistoryService } from './word.history.service';

@Component({
  selector: 'word-history',
  templateUrl: './word.history.html',
  styles: [`
  `],
  providers: [WordDetailHistoryService]
})


export class WordDetailHistoryComponent {

  wordInfo: any;
  constructor(private util: Util, private service: WordDetailHistoryService) {


    this.wordInfo = this.util.sessionStore().get('wordDetail');

    console.log(this.wordInfo);

    this.vm.loading = true;

    this.getHttp(this.wordInfo, {});
  }

  vm = {
    "loading": true,
    "fileName": '',
    "data": [],
    "type": "line-word"
  };

  columns = ['时间', '日销售额', '日销售量', '近30天销售额', '近30天销售量', '动销宝贝数', '最热指数', '最新指数'];


  ngOnDestroy() {
    if (this.offEvent) {
      this.offEvent.unsubscribe();

    }
  }


  export() {
    console.log("export");

    let dim = ['date', 'words', 'categoryName', 'sellMoney', 'sellAmount', 'monthSellMoney', 'monthSellAmount', 'productNum', 'productSellMoneyGrowth', 'productSellMoneyDecrease', 'sellGrowthProductNum', 'sellDecreaseProductNum', 'hotIndexNumber', 'growthIndexNumber'];

    let dimText = ['时间', '词云', '类目', '日销售额', '日销售量', '近30天销售额', '近30天销售量', '动销宝贝数', 'productSellMoneyGrowth', 'productSellMoneyDecrease', 'sellGrowthProductNum', 'sellDecreaseProductNum', 'hotIndexNumber'];

    let data = this.util.jsonToArrry(this.vm.data, dim, dimText);
    let sheetName: string;
    try {
      sheetName = this.httpParam.begin.slice(0, 10) + '~' + this.httpParam.end.slice(0, 10) + this.wordInfo.words;
    } catch (e) {
      sheetName = this.wordInfo.words;
    }

    this.util.export(data, sheetName);
  }

  // 日期的处理
  dateOnChange(data) {

    // console.log(data);

    this.vm.loading = true;

    this.getHttp(this.wordInfo, data);

  }



  httpParam: any;
  offEvent: any;
  getHttp(wordInfo, date) {

    let json = {
      word: wordInfo.words,
      categoryId: wordInfo.categoryId,
      type: wordInfo.type
    };

    Object.assign(json, date);

    this.httpParam = json;

    let res = {
      "code": 0,
      "msg": "成功", "data": [{ "id": "50019780\u00012018-04-01 00:00:00\u0001智能全网通", "date": "2018-04-01 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 5, "monthSellAmount": 196, "sellMoney": 4295.0, "monthSellMoney": 179804.0, "productNum": 2, "productSellMoneyGrowth": 0.0, "productSellMoneyDecrease": 5154.0, "sellGrowthProductNum": 0, "sellDecreaseProductNum": 1, "hotIndexNumber": 24.49, "growthIndexNumber": -8.47 }, { "id": "50019780\u00012018-04-26 00:00:00\u0001智能全网通", "date": "2018-04-26 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 12, "monthSellAmount": 202, "sellMoney": 28669.0, "monthSellMoney": 338689.0, "productNum": 7, "productSellMoneyGrowth": 26871.0, "productSellMoneyDecrease": 8013.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 2, "hotIndexNumber": 39.24, "growthIndexNumber": 13.94 }, { "id": "50019780\u00012018-04-27 00:00:00\u0001智能全网通", "date": "2018-04-27 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 25, "monthSellAmount": 219, "sellMoney": 71363.0, "monthSellMoney": 403180.0, "productNum": 7, "productSellMoneyGrowth": 68666.0, "productSellMoneyDecrease": 4175.0, "sellGrowthProductNum": 3, "sellDecreaseProductNum": 1, "hotIndexNumber": 40.99, "growthIndexNumber": 18.95 }, { "id": "50019780\u00012018-04-28 00:00:00\u0001智能全网通", "date": "2018-04-28 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 13, "monthSellAmount": 226, "sellMoney": 37476.0, "monthSellMoney": 433422.0, "productNum": 9, "productSellMoneyGrowth": 35678.0, "productSellMoneyDecrease": 5436.0, "sellGrowthProductNum": 5, "sellDecreaseProductNum": 2, "hotIndexNumber": 44.44, "growthIndexNumber": 17.36 }, { "id": "50019780\u00012018-04-29 00:00:00\u0001智能全网通", "date": "2018-04-29 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 21, "monthSellAmount": 244, "sellMoney": 70558.0, "monthSellMoney": 500363.0, "productNum": 9, "productSellMoneyGrowth": 70558.0, "productSellMoneyDecrease": 3617.0, "sellGrowthProductNum": 3, "sellDecreaseProductNum": 2, "hotIndexNumber": 46.07, "growthIndexNumber": 16.09 }, { "id": "50019780\u00012018-04-30 00:00:00\u0001智能全网通", "date": "2018-04-30 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 14, "monthSellAmount": 257, "sellMoney": 41065.0, "monthSellMoney": 540569.0, "productNum": 9, "productSellMoneyGrowth": 40206.0, "productSellMoneyDecrease": 0.0, "sellGrowthProductNum": 3, "sellDecreaseProductNum": 0, "hotIndexNumber": 46.96, "growthIndexNumber": 18.64 }, { "id": "50019780\u00012018-05-01 00:00:00\u0001智能全网通", "date": "2018-05-01 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 26, "monthSellAmount": 278, "sellMoney": 69896.0, "monthSellMoney": 606170.0, "productNum": 9, "productSellMoneyGrowth": 65601.0, "productSellMoneyDecrease": 0.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 0, "hotIndexNumber": 48.33, "growthIndexNumber": 22.63 }, { "id": "50019780\u00012018-05-02 00:00:00\u0001智能全网通", "date": "2018-05-02 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 16, "monthSellAmount": 289, "sellMoney": 32204.0, "monthSellMoney": 634079.0, "productNum": 9, "productSellMoneyGrowth": 27909.0, "productSellMoneyDecrease": 0.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 0, "hotIndexNumber": 48.88, "growthIndexNumber": 18.28 }, { "id": "50019780\u00012018-05-03 00:00:00\u0001智能全网通", "date": "2018-05-03 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 19, "monthSellAmount": 301, "sellMoney": 55512.0, "monthSellMoney": 681498.0, "productNum": 9, "productSellMoneyGrowth": 55512.0, "productSellMoneyDecrease": 8093.0, "sellGrowthProductNum": 3, "sellDecreaseProductNum": 3, "hotIndexNumber": 49.77, "growthIndexNumber": 0.0 }, { "id": "50019780\u00012018-05-04 00:00:00\u0001智能全网通", "date": "2018-05-04 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 17, "monthSellAmount": 310, "sellMoney": 32579.0, "monthSellMoney": 705125.0, "productNum": 9, "productSellMoneyGrowth": 30002.0, "productSellMoneyDecrease": 6375.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 2, "hotIndexNumber": 50.19, "growthIndexNumber": 14.74 }, { "id": "50019780\u00012018-05-05 00:00:00\u0001智能全网通", "date": "2018-05-05 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 22, "monthSellAmount": 328, "sellMoney": 39564.0, "monthSellMoney": 741253.0, "productNum": 9, "productSellMoneyGrowth": 36128.0, "productSellMoneyDecrease": 0.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 0, "hotIndexNumber": 50.82, "growthIndexNumber": 19.5 }, { "id": "50019780\u00012018-05-06 00:00:00\u0001智能全网通", "date": "2018-05-06 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 17, "monthSellAmount": 342, "sellMoney": 37776.0, "monthSellMoney": 776332.0, "productNum": 9, "productSellMoneyGrowth": 37776.0, "productSellMoneyDecrease": 2697.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 1, "hotIndexNumber": 51.41, "growthIndexNumber": 18.01 }, { "id": "50019780\u00012018-05-07 00:00:00\u0001智能全网通", "date": "2018-05-07 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 19, "monthSellAmount": 359, "sellMoney": 47564.0, "monthSellMoney": 822098.0, "productNum": 9, "productSellMoneyGrowth": 45846.0, "productSellMoneyDecrease": 80.0, "sellGrowthProductNum": 3, "sellDecreaseProductNum": 1, "hotIndexNumber": 52.15, "growthIndexNumber": 17.39 }, { "id": "50019780\u00012018-05-08 00:00:00\u0001智能全网通", "date": "2018-05-08 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 20, "monthSellAmount": 376, "sellMoney": 53742.0, "monthSellMoney": 871143.0, "productNum": 9, "productSellMoneyGrowth": 52843.0, "productSellMoneyDecrease": 3798.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 1, "hotIndexNumber": 52.92, "growthIndexNumber": 19.59 }, { "id": "50019780\u00012018-05-09 00:00:00\u0001智能全网通", "date": "2018-05-09 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 26, "monthSellAmount": 399, "sellMoney": 58774.0, "monthSellMoney": 927220.0, "productNum": 9, "productSellMoneyGrowth": 56077.0, "productSellMoneyDecrease": 0.0, "sellGrowthProductNum": 5, "sellDecreaseProductNum": 0, "hotIndexNumber": 53.75, "growthIndexNumber": 23.01 }, { "id": "50019780\u00012018-05-10 00:00:00\u0001智能全网通", "date": "2018-05-10 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 19, "monthSellAmount": 415, "sellMoney": 31912.0, "monthSellMoney": 956435.0, "productNum": 9, "productSellMoneyGrowth": 29215.0, "productSellMoneyDecrease": 0.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 0, "hotIndexNumber": 54.17, "growthIndexNumber": 18.49 }, { "id": "50019780\u00012018-05-11 00:00:00\u0001智能全网通", "date": "2018-05-11 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 12, "monthSellAmount": 424, "sellMoney": 28568.0, "monthSellMoney": 982306.0, "productNum": 9, "productSellMoneyGrowth": 27709.0, "productSellMoneyDecrease": 1838.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 1, "hotIndexNumber": 54.53, "growthIndexNumber": 16.69 }, { "id": "50019780\u00012018-05-12 00:00:00\u0001智能全网通", "date": "2018-05-12 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 18, "monthSellAmount": 438, "sellMoney": 46766.0, "monthSellMoney": 1025476.0, "productNum": 9, "productSellMoneyGrowth": 45048.0, "productSellMoneyDecrease": 1878.0, "sellGrowthProductNum": 5, "sellDecreaseProductNum": 1, "hotIndexNumber": 55.12, "growthIndexNumber": 20.38 }, { "id": "50019780\u00012018-05-13 00:00:00\u0001智能全网通", "date": "2018-05-13 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 9, "monthSellAmount": 442, "sellMoney": 15374.0, "monthSellMoney": 1036355.0, "productNum": 9, "productSellMoneyGrowth": 13656.0, "productSellMoneyDecrease": 2777.0, "sellGrowthProductNum": 2, "sellDecreaseProductNum": 1, "hotIndexNumber": 55.26, "growthIndexNumber": 10.21 }, { "id": "50019780\u00012018-05-14 00:00:00\u0001智能全网通", "date": "2018-05-14 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 200, "monthSellAmount": 4261, "sellMoney": 65600.0, "monthSellMoney": 2354388.0, "productNum": 10, "productSellMoneyGrowth": 0.0, "productSellMoneyDecrease": 18667.0, "sellGrowthProductNum": 0, "sellDecreaseProductNum": 2, "hotIndexNumber": 69.66, "growthIndexNumber": -13.9 }, { "id": "50019780\u00012018-05-15 00:00:00\u0001智能全网通", "date": "2018-05-15 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 100, "monthSellAmount": 4137, "sellMoney": 32800.0, "monthSellMoney": 2299108.0, "productNum": 9, "productSellMoneyGrowth": 0.0, "productSellMoneyDecrease": 52981.0, "sellGrowthProductNum": 0, "sellDecreaseProductNum": 2, "hotIndexNumber": 67.45, "growthIndexNumber": -18.04 }, { "id": "50019780\u00012018-05-16 00:00:00\u0001智能全网通", "date": "2018-05-16 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 200, "monthSellAmount": 4125, "sellMoney": 65600.0, "monthSellMoney": 2281382.0, "productNum": 9, "productSellMoneyGrowth": 0.0, "productSellMoneyDecrease": 17726.0, "sellGrowthProductNum": 0, "sellDecreaseProductNum": 2, "hotIndexNumber": 67.31, "growthIndexNumber": -13.72 }, { "id": "50019780\u00012018-05-17 00:00:00\u0001智能全网通", "date": "2018-05-17 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 222, "monthSellAmount": 4138, "sellMoney": 142336.0, "monthSellMoney": 2342558.0, "productNum": 9, "productSellMoneyGrowth": 76736.0, "productSellMoneyDecrease": 15560.0, "sellGrowthProductNum": 1, "sellDecreaseProductNum": 2, "hotIndexNumber": 67.76, "growthIndexNumber": -15.73 }, { "id": "50019780\u00012018-05-18 00:00:00\u0001智能全网通", "date": "2018-05-18 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 310, "monthSellAmount": 4283, "sellMoney": 153148.0, "monthSellMoney": 2416200.0, "productNum": 9, "productSellMoneyGrowth": 77130.0, "productSellMoneyDecrease": 3488.0, "sellGrowthProductNum": 5, "sellDecreaseProductNum": 1, "hotIndexNumber": 68.29, "growthIndexNumber": 23.3 }, { "id": "50019780\u00012018-05-19 00:00:00\u0001智能全网通", "date": "2018-05-19 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 188, "monthSellAmount": 4327, "sellMoney": 89216.0, "monthSellMoney": 2435630.0, "productNum": 9, "productSellMoneyGrowth": 32016.0, "productSellMoneyDecrease": 12586.0, "sellGrowthProductNum": 5, "sellDecreaseProductNum": 1, "hotIndexNumber": 68.42, "growthIndexNumber": 16.7 }, { "id": "50019780\u00012018-05-20 00:00:00\u0001智能全网通", "date": "2018-05-20 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 247, "monthSellAmount": 4449, "sellMoney": 100916.0, "monthSellMoney": 2477004.0, "productNum": 9, "productSellMoneyGrowth": 43172.0, "productSellMoneyDecrease": 1798.0, "sellGrowthProductNum": 3, "sellDecreaseProductNum": 1, "hotIndexNumber": 68.71, "growthIndexNumber": 16.96 }, { "id": "50019780\u00012018-05-21 00:00:00\u0001智能全网通", "date": "2018-05-21 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 253, "monthSellAmount": 4573, "sellMoney": 113434.0, "monthSellMoney": 2529424.0, "productNum": 9, "productSellMoneyGrowth": 54218.0, "productSellMoneyDecrease": 1798.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 1, "hotIndexNumber": 69.07, "growthIndexNumber": 19.91 }, { "id": "50019780\u00012018-05-22 00:00:00\u0001智能全网通", "date": "2018-05-22 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 235, "monthSellAmount": 4666, "sellMoney": 106322.0, "monthSellMoney": 2538817.0, "productNum": 9, "productSellMoneyGrowth": 52148.0, "productSellMoneyDecrease": 42755.0, "sellGrowthProductNum": 3, "sellDecreaseProductNum": 2, "hotIndexNumber": 69.14, "growthIndexNumber": 9.84 }, { "id": "50019780\u00012018-05-23 00:00:00\u0001智能全网通", "date": "2018-05-23 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 228, "monthSellAmount": 4756, "sellMoney": 89607.0, "monthSellMoney": 2559730.0, "productNum": 9, "productSellMoneyGrowth": 34865.0, "productSellMoneyDecrease": 13952.0, "sellGrowthProductNum": 4, "sellDecreaseProductNum": 1, "hotIndexNumber": 69.28, "growthIndexNumber": 15.83 }, { "id": "50019780\u00012018-05-24 00:00:00\u0001智能全网通", "date": "2018-05-24 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 10, "monthSellAmount": 4622, "sellMoney": 27012.0, "monthSellMoney": 2519170.0, "productNum": 9, "productSellMoneyGrowth": 6084.0, "productSellMoneyDecrease": 46644.0, "sellGrowthProductNum": 3, "sellDecreaseProductNum": 1, "hotIndexNumber": 69.0, "growthIndexNumber": -16.88 }, { "id": "50019780\u00012018-05-25 00:00:00\u0001智能全网通", "date": "2018-05-25 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 92, "monthSellAmount": 4564, "sellMoney": 37762.0, "monthSellMoney": 2483567.0, "productNum": 9, "productSellMoneyGrowth": 939.0, "productSellMoneyDecrease": 36542.0, "sellGrowthProductNum": 1, "sellDecreaseProductNum": 3, "hotIndexNumber": 68.76, "growthIndexNumber": -16.34 }, { "id": "50019780\u00012018-05-26 00:00:00\u0001智能全网通", "date": "2018-05-26 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 82, "monthSellAmount": 4507, "sellMoney": 39536.0, "monthSellMoney": 2451508.0, "productNum": 9, "productSellMoneyGrowth": 3488.0, "productSellMoneyDecrease": 35547.0, "sellGrowthProductNum": 1, "sellDecreaseProductNum": 6, "hotIndexNumber": 68.54, "growthIndexNumber": -20.01 }, { "id": "50019780\u00012018-05-27 00:00:00\u0001智能全网通", "date": "2018-05-27 00:00:00", "categoryId": "50019780", "categoryName": "数码/手机/家电--平板电脑/MID", "categoryLevel": 2, "words": "智能全网通", "sellAmount": 89, "monthSellAmount": 4423, "sellMoney": 42403.0, "monthSellMoney": 2372524.0, "productNum": 9, "productSellMoneyGrowth": 899.0, "productSellMoneyDecrease": 79883.0, "sellGrowthProductNum": 1, "sellDecreaseProductNum": 5, "hotIndexNumber": 67.98, "growthIndexNumber": -23.71 }]
    };



    // this.vm.fileName = this.httpParam.begin.slice(0, 10) + '~' + this.httpParam.end.slice(0, 10) + this.wordInfo.words;

    this.vm.data = res.data;

    setTimeout(() => {
      this.vm.loading = false;
    }, 1000);



  }

}
